<?php
/* @var $this ReleaseController */
/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(
	'messages',
);

?>

<!-- Page Head -->
			<h2><?php echo CHtml::link("消息操作",$this->createUrl("user/index"));?></h2>
					<?php echo $this->renderPartial("topMenu");?>
			
			<div class="content-box">
			<!-- Start Content Box -->
				
				<div class="content-box-header">
					
					<h3>消息信息列表</h3>
				
					<div class="clear"></div>
					
				</div> <!-- End .content-box-header -->				
				<div class="content-box-content" >
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('message-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php
	function showsendmessage($data)
	{
		if($data->MsgSended==0 && $data->MsgSender==0 ){
			return true;
		}
		return false;
	}
?>
<div class="search-form">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'message-grid',
	'dataProvider'=>$model->search(),
	'cssFile'=>Yii::app()->theme->baseUrl."/resources/css/style.css",
	'columns'=>array(
		'Titile',
		'Content',
		array(
				'name'=>'Msgtype',
				'value'=>'Yii::app()->params["Msgtype"][$data->Msgtype]',
		),
		'UserName',
		array(
			'name'=>'MsgSended',
			'value'=>'Yii::app()->params["MsgSended"][$data->MsgSended]',
		),
		array(
			'name'=>'Created',
			'value'=>'date("Y-m-d H:i:s",$data->Created)',
		),
		array(
			'class'=>'CButtonColumn',
            'header'=>'操作',
			'template'=>'{sendmessage}{view}{update}{delete}',
			'afterDelete'=>'function(link,success,data){ if(success) alert("数据删除成功"); }',
			'buttons'=>array(
				'sendmessage'=>array(
					'imageUrl'=>Yii::app()->theme->baseUrl."/resources/images/icons/sendmessage.png",
					'visible'=>'showsendmessage($data);',
					'url'=>'Yii::app()->createUrl("message/sendmessage",array("id"=>$data->Id))',
					'options'=>array('class'=>'sendmessage'),
				),
				'update'=>array(
					'visible'=>'showsendmessage($data);',
				),
				'delete'=>array(
					'options'=>array('onclick'=>'return false;'),
				),

			),

		),
	),
	
)); ?>
</div> <!-- End .content-box-content -->
</div> <!-- End .content-box -->
<div class="clear"></div>
<script type="text/javascript">
<!--
	$(document).on('click','#message-grid a.sendmessage',function() {
	if(!confirm('确定要发送此条信息吗?')) return false;
	var th=this;
	var afterDelete=function(link,success,data){ if(success) alert("信息发送成功"); };
	$.fn.yiiGridView.update('message-grid', {
		type:'POST',
		url:$(this).attr('href'),
		success:function(data) {
			$.fn.yiiGridView.update('message-grid');
			afterDelete(th,true,data);
		},
		error:function(XHR) {
			return afterDelete(th,false,XHR);
		}
	});
	return false;
});
//-->
</script>